package config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 发布订阅模式的配置,包括两个队列和对应的订阅者,发布者的交换机类型使用fanout(子网广播),两根网线binding用来绑定队列到交换机
 * 
 * @author super
 *
 */
@Configuration
public class FanoutExchangeConfig {
	/** 发布订阅模式-队列1 */
	public static final String QUEUE_NANE_1 = "queue1";
	
	/** 发布订阅模式-队列2 */
	public static final String QUEUE_NANE_2 = "queue2";
	
	@Autowired
	RabbitConfig rabbitconfig;

	@Bean
	public Queue myQueue1() {
		Queue queue = new Queue(QUEUE_NANE_1);
		return queue;
	}

	@Bean
	public Queue myQueue2() {
		Queue queue = new Queue(QUEUE_NANE_2);
		return queue;
	}

	@Bean
	public FanoutExchange fanoutExchange() {
		// 声明转发器和类型
		FanoutExchange fanoutExchange = new FanoutExchange("fanout");
		return fanoutExchange;
	}

	@Bean
	public Binding binding1() {
		Binding binding = BindingBuilder.bind(myQueue1()).to(fanoutExchange());
		return binding;
	}

	@Bean
	public Binding binding2() {
		Binding binding = BindingBuilder.bind(myQueue2()).to(fanoutExchange());
		return binding;
	}

}
